__author__ = 'st316'
'''
Divide two integers without using multiplication, division and mod operator.
+ - 移位操作
'''


class Solution:
    # @return an integer
    def divide(self, dividend, divisor):
        if dividend == 0 or divisor == 0:
            return 0
        a = abs(dividend)
        b = abs(divisor)
        s = 1 if dividend ^ divisor >= 0 else -1
        res = 0
        while a >= b:
            c = b
            i = 0
            while a >= c:
                a -= c
                res += 1 << i
                i += 1
                c <<= 1
        return s * res


if __name__ == '__main__':
    s = Solution()
    print s.divide(-1, 1)